home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
tex
/
dvi
/
dvipssrc.zoo
/
resident.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-01-20
|
19KB
|
741 lines
/*
* This code reads in and handles the defaults for the program from the
* file config.sw. This entire file is a bit kludgy, sorry.
*/
#include "structures.h" /* The copyright notice in that file is included too! */
#include "paths.h"
/*
* This is the structure definition for resident fonts. We use
* a small and simple hash table to handle these. We don't need
* a big hash table.
*/
struct resfont *reshash[RESHASHPRIME] ;
/*
* These are the external routines we use.
*/
extern void error() ;
extern integer scalewidth() ;
extern void tfmload() ;
extern FILE *search() ;
extern shalfword pkbyte() ;
extern integer pkquad() ;
extern integer pktrio() ;
extern Boolean pkopen() ;
extern char *strcpy() ;
extern char *getenv() ;
extern char *newstring() ;
extern int add_header() ;
extern int add_name() ;
extern char *get_name() ;
extern int system() ;
/*
* These are the external variables we use.
*/
#ifdef DEBUG
extern integer debug_flag;
#endif /* DEBUG */
extern long bytesleft ;
extern quarterword *raster ;
extern FILE *pkfile ;
extern char *oname ;
extern integer swmem, fontmem ;
extern char *tfmpath ;
extern char *pkpath ;
extern char *vfpath ;
extern char *figpath ;
extern char *configpath ;
#ifdef SEARCH_SUBDIRECTORIES
extern char *fontsubdirpath ;
#endif
#ifdef FONTLIB
extern char *flipath, *fliname ;
#endif
extern char *headerpath ;
extern char *paperfmt ;
extern char *nextstring ;
extern char *maxstring ;
extern char *warningmsg ;
extern Boolean disablecomments ;
extern Boolean compressed ;
extern int quiet ;
extern int filter ;
extern Boolean reverse ;
extern Boolean usesPSfonts ;
extern Boolean nosmallchars ;
extern Boolean removecomments ;
extern Boolean safetyenclose ;
extern int actualdpi ;
extern int vactualdpi ;
extern int maxdrift ;
extern int vmaxdrift ;
extern char *printer ;
extern char *mfmode ;
extern int lastresortsizes[] ;
/*
* To maintain a list of document fonts, we use the following
* pointer.
*/
struct header_list *ps_fonts_used ;
/*
* We use malloc here.
*/
char *malloc() ;
/*
* Our hash routine.
*/
int
hash(s)
char *s ;
{
int h = 12 ;
while (*s != 0)
h = (h + h + *s++) % RESHASHPRIME ;
return(h) ;
}
/*
* cleanres() marks all resident fonts as not being yet sent.
*/
void
cleanres() {
register int i ;
register struct resfont *p ;
for (i=0; i<RESHASHPRIME; i++)
for (p=reshash[i]; p; p=p->next)
p->sent = 0 ;
}
/*
* The routine that looks up a font name.
*/
struct resfont *
lookup(name)
char *name ;
{
struct resfont *p ;
for (p=reshash[hash(name)]; p!=NULL; p=p->next)
if (strcmp(p->Keyname, name)==0)
return(p) ;
return(NULL) ;
}
/*
* This routine adds an entry.
*/
void
add_entry(Keyname, TeXname, PSname, specinfo, downloadinfo)
char *Keyname, *TeXname, *PSname, *specinfo, *downloadinfo ;
{
struct resfont *p ;
int h ;
if (PSname == NULL)
PSname = TeXname ;
else if (strcmp(PSname, TeXname) && Keyname != PSname)
add_entry(PSname, TeXname, PSname, specinfo, downloadinfo) ;
p = (struct resfont *)malloc((unsigned int)sizeof(struct resfont)) ;
if (p==NULL)
error("! out of memory") ;
p->Keyname = Keyname ;
p->PSname = PSname ;
p->TeXname = TeXname ;
p->specialinstructions = specinfo ;
p->downloadheader = downloadinfo ;
h = hash(Keyname) ;
p->next = reshash[h] ;
p->sent = 0 ;
reshash[h] = p ;
}
/*
* Now our residentfont routine.
*/
Boolean
residentfont(curfnt)
register fontdesctype *curfnt ;
{
register shalfword i ;
struct resfont *p ;
/*
* First we determine if we can find this font in the resident list.
*/
if (*curfnt->area)
return 0 ; /* resident fonts never have a nonstandard font area */
if ((p=lookup(curfnt->name))==NULL)
return 0 ;
/*
* We clear out some pointers:
*/
#ifdef DEBUG
if (dd(D_FONTS))
(void)fprintf(stderr,"Font %s <%s> is resident.\n",
curfnt->name, p->PSname) ;
#endif /* DEBUG */
curfnt->resfont = p ;
curfnt->name = p->TeXname ;
for (i=0; i<256; i++) {
curfnt->chardesc[i].TFMwidth = 0 ;
curfnt->chardesc[i].packptr = NULL ;
curfnt->chardesc[i].pixelwidth = 0 ;
curfnt->chardesc[i].flags = 0 ;
}
add_name(p->PSname, &ps_fonts_used) ;
/*
* We include the font here. But we only should need to include the
* font if we have a stupid spooler; smart spoolers should be able
* to supply it automatically.
*/
if (p->downloadheader)
if (add_header(p->downloadheader)) {
swmem -= DNFONTCOST ;
fontmem -= DNFONTCOST ;
}
tfmload(curfnt) ;
usesPSfonts = 1 ;
return(1) ;
}
#define INLINE_SIZE (500)
static char was_inline[INLINE_SIZE] ;
void
bad_config() {
extern void exit() ;
error("Error in config file:") ;
(void)fputs(was_inline, stderr) ;
exit(1) ;
}
/*
* Now we have the getdefaults routine.
*/
static char *psmapfile = PSMAPFILE ;
void
getdefaults(s)
char *s ;
{
FILE *deffile ;
char PSname[300] ;
register char *p ;
int i, j ;
char *d = configpath ;
if (printer == NULL) {
if (s) {
strcpy(PSname, s) ;
} else {
d = "~" ;
strcpy(PSname, DVIPSRC) ;
}
} else {
strcpy(PSname, "config.") ;
strcat(PSname, printer) ;
}
if ((deffile=search(d,PSname,READ))!=NULL) {
while (fgets(was_inline, INLINE_SIZE, deffile)!=NULL) {
/*
* We need to get rid of the newline.
*/
for (p=was_inline; *p; p++) ;
if (p > was_inline) *(p-1) = 0 ;
switch (was_inline[0]) {
case 'm' :
#ifdef SHORTINT
if (sscanf(was_inline+1, "%ld", &swmem) != 1) bad_config() ;
#else /* ~SHORTINT */
if (sscanf(was_inline+1, "%d", &swmem) != 1) bad_config() ;
#endif /* ~SHORTINT */
break ;
case 'M' :
if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
mfmode = newstring(PSname) ;
break ;
case 'o' : case 'O' :
p = was_inline + 1 ;
#ifdef VMS
p[strlen(p) - 1] = '\0';
#endif /* VMS */
while (*p && *p <= ' ')
p++ ;
oname = newstring(p) ;
break ;
#ifdef FONTLIB
case 'L' :
{
char tempname[300] ;
extern char *fliparse() ;
if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
else {
flipath = newstring(fliparse(PSname,tempname));
fliname = newstring(tempname) ;
}
}
break ;
#endif
case 'T' :
if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
else tfmpath = newstring(PSname) ;
break ;
case 'P' :
if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
else pkpath = newstring(PSname) ;
break ;
case 'p' :
if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
else psmapfile = newstring(PSname) ;
break ;
case 'V' : case 'v' :
if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
else vfpath = newstring(PSname) ;
break ;
case 'S' :
if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
else figpath = newstring(PSname) ;
break ;
case 's':
safetyenclose = 1 ;
break ;
case 'H' :
if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
else headerpath = newstring(PSname) ;
break ;
case 't' :
if (sscanf(was_inline+1, "%s", PSname) != 1) bad_config() ;
else paperfmt = newstring(PSname) ;
break ;
case ' ' : case '*' : case '#' : case ';' : case '=' : case 0 : case '\n' :
break ;
case 'r' :
reverse = (was_inline[1] != '0') ;
break ;
/*
* This case is for last resort font scaling; I hate this, but enough
* people have in no uncertain terms demanded it that I'll go ahead and
* add it.
*
* This line must have numbers on it, resolutions, to search for the
* font as a last resort, and then the font will be scaled. These
* resolutions should be in increasing order.
*
* For most machines, just `30